package models

import (
	"time"

	"gorm.io/gorm"
)

// SystemLog 系统访问日志
type SystemLog struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	UserID    uint      `gorm:"column:user_id" json:"user_id"`
	Action    string    `gorm:"size:255" json:"action"`
	IP        string    `gorm:"size:64" json:"ip"`
	Status    int       `gorm:"column:status" json:"status"`
	Detail    string    `gorm:"type:text" json:"detail"`
	CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
}

// AuditLog AI分析结果
type AuditLog struct {
	ID        uint      `gorm:"primaryKey"`
	Date      time.Time `gorm:"index;comment:分析日期"`
	Summary   string    `gorm:"type:text;comment:分析摘要"`
	RiskLevel string    `gorm:"size:50;comment:风险等级"`
	Details   string    `gorm:"type:longtext;comment:分析详情"`
	CreatedAt time.Time
}

// GetSystemLogs 获取所有系统行为日志
func GetSystemLogs(db *gorm.DB) ([]SystemLog, error) {
	var logs []SystemLog
	if err := db.Order("created_at desc").Find(&logs).Error; err != nil {
		return nil, err
	}
	return logs, nil
}

// GetAuditLogs 获取AI分析记录
func GetAuditLogs(db *gorm.DB) ([]AuditLog, error) {
	var audits []AuditLog
	if err := db.Order("date desc").Find(&audits).Error; err != nil {
		return nil, err
	}
	return audits, nil
}
